package com.espoir.util;

import com.espoir.shp.read02.Point;

/**
 * WKT 格式数据转化工具
 *
 */
public class WKTUtils {

    /**
     *  wktPoint 字符串（POINT(123 123) ） 中提取 x,y 坐标，封装为 Point 对象
     * @param wktPoint
     * @return
     */
    public static Point wktPointToPoint(String wktPoint){
        String xy = wktPoint.substring(wktPoint.indexOf("(")+1,wktPoint.indexOf(")"));
        String[] xyStr = xy.split(" ");
        Point p = new Point(Double.parseDouble(xyStr[0]), Double.parseDouble(xyStr[1]));
        return p;
    }

    /**
     * Point 对象转化成 wktPoint 字符串（POINT(123 123) ）
     * @param point
     * @return
     */
    public static String PointToWKTPoint(Point point){
        double x = point.getX();
        double y = point.getY();
        String wktPoint =  "POINT("+x+" "+y +")";
        return wktPoint;
    }
}


